package com.dapao.service.impl;

import com.dapao.mapper.GoodMapper;
import com.dapao.pojo.Good;
import com.dapao.pojo.Match;
import com.dapao.pojo.PageBean;
import com.dapao.service.GoodService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List;

@Service
public class GoodServiceImpl implements GoodService {

    @Autowired
    private GoodMapper goodMapper;

    @Override
    public PageBean page(Integer page, String goodKeyValue , Integer sellerId) {
        //1.设置分页参数
        PageHelper.startPage(page, 6);
        //2.执行查询
        List<Good> empList = goodMapper.page(goodKeyValue,sellerId);
        Page<Good> p = (Page<Good>) empList;
        PageBean pageBean = new PageBean(p.getTotal(), p.getResult());
        return pageBean;
    }

    @Override
    public Good detail(Integer id) {
        return goodMapper.detail(id);
    }

    @Override
    public void addGood(Good good) {
        good.setTime(LocalDate.now());
        goodMapper.addGood(good);
    }

    @Override
    public void deleteGood(Integer id) {
        goodMapper.deleteGood(id);
    }
}
